package com.gcb.controller.company;

import com.gcb.common.annotation.Log;
import com.gcb.common.core.domain.AjaxResult;
import com.gcb.common.enums.BusinessType;
import com.gcb.controller.BaseController;
import com.gcb.domain.dto.company.CompanyAuthDTO;
import com.gcb.domain.dto.company.CompanyWaterAuthDTO;
import com.gcb.framework.utils.SecurityUtils;
import com.gcb.service.ICompanyAuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 企业信息Controller
 *
 * @author seh
 * @since 2024-03-08
 */
@RestController
@RequestMapping("/company")
public class CompanyAuthController extends BaseController {

    @Resource
    private ICompanyAuthService companyAuthService;

    /**
     * 查询企业认证+水路运营认证信息
     */
    @PreAuthorize("@ss.hasPermi('company:auth:query')")
    @GetMapping(value = "/auth/{id}")
    public AjaxResult getAuth(@PathVariable("id") Long id) {
        return success(companyAuthService.getAuth(id));
    }

    /**
     * 新增/编辑企业认证
     */
    @PreAuthorize("@ss.hasPermi('company:auth:form')")
    @Log(title = "企业认证信息", businessType = BusinessType.INSERT)
    @PostMapping("/auth")
    public AjaxResult saveAuth(@RequestBody CompanyAuthDTO dto) {
        return companyAuthService.saveAuth(dto, SecurityUtils.getUserId()) ? AjaxResult.success() : AjaxResult.error();
    }

    @PreAuthorize("@ss.hasPermi('company:waterAuth:form')")
    @Log(title = "企业船运资质认证信息", businessType = BusinessType.INSERT)
    @PostMapping("/waterAuth")
    public AjaxResult saveWaterAuth(@RequestBody CompanyWaterAuthDTO dto) {
        return companyAuthService.saveWaterAuth(dto, SecurityUtils.getUserId()) ? AjaxResult.success() : AjaxResult.error();
    }

}
